require 'gamebase.common'

Button = {}

function Button:Init(_x,_y,_w,_h,_text)
	local button = 
	{
		x = _x,
		y = _y,
		w = _w,
		h = _h,
	
		colorRect = {200,200,55,255},
		colorBorder = {255,255,255,255},
	
		text = _text
	}
	setmetatable(button, { __index = Button })
	return button
end

function Button:Update()
	local MouseBox = {}
	
	MouseBox.x = love.mouse.getX()
	MouseBox.y = love.mouse.getY()
	MouseBox.w = 1
	MouseBox.h = 1
	
	if Common:Collision(MouseBox,self) and love.mouse.wasReleased("l") then
		return true
	end
	
	return false
end

function Button:Draw()
		--draw the button
		love.graphics.setColor(self.colorRect)
		love.graphics.rectangle("fill",self.x, self.y, self.w, self.h)
		
		-- draw the button border
		love.graphics.setColor(self.colorBorder)
		love.graphics.rectangle("line",self.x, self.y, self.w, self.h)
		
		--draw the buttons text
		local centerx = self.x + 9
		local centery = self.y + 6
		
		love.graphics.print(self.text, centerx, centery)
		
		love.graphics.setColor(255,255,255)
		
end
